package kiwi.assist.dev.util {
	import ghostcat.operation.load.LoadOper;
	import ghostcat.util.text.URL;

	import flash.display.Loader;
	import flash.events.Event;
	import flash.system.ApplicationDomain;
	import flash.system.LoaderContext;

	/**
	 * 加载SWF的操作哦
	 * @author zhangming.luo
	 */
	public class LoadSWFOper extends LoadOper {
		public function LoadSWFOper(url : * = null, embedClass : Class = null, rhandler : Function = null, fhandler : Function = null) {
			super(url, embedClass, rhandler, fhandler);
		}

		override protected function urlLoadCompleteHandler(event : Event = null) : void {
			_urlLoader.removeEventListener(Event.COMPLETE, urlLoadCompleteHandler);

			var isLoader : Boolean;
			if (this.type == AUTO && request)
				isLoader = (LOADER_TYPE.indexOf(new URL(request.url).pathname.extension) != -1);
			else
				isLoader = (this.type == LOADER);

			if (isLoader) {
				_loader = new Loader();
				_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, result);
				_loader.contentLoaderInfo.addEventListener(Event.INIT, initHandler);
				var context : LoaderContext = new LoaderContext(false, useCurrentDomain ? ApplicationDomain.currentDomain : null);
				if (context.hasOwnProperty("allowLoadBytesCodeExecution")) {
					context["allowLoadBytesCodeExecution"] = true;
				}
				_loader.loadBytes(this.bytes, context);
			} else {
				result(event ? event : new Event(Event.COMPLETE));
			}
		}
	}
}
